package com.xjd.io.in;

import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * <pre>
 * 当调用skip(n)方法时，让InputStream必须跳过指n个字节
 *   若当前可读字节小于n，则跳过所有可读字节
 *   若当前要读字节大于或等于n，则跳过n个字节
 * </pre>
 * @author  elvis.xu
 * @version 2013-1-9 上午11:50:35
 */
public class FixSkipInputStream extends IsEndInputStream {

	public FixSkipInputStream(InputStream in) {
		super(in);
	}

	@Override
	public long skip(long n) throws IOException {
		long remain = n;
		while (!isEnd() && remain > 0) {
			long skipped = super.skip(remain);
			remain -= skipped;
		}
		return n - remain;
	}

}
